﻿using PhoneStoreWeb.Models;
using System.Collections.Generic;
using System.Linq;
using System.Data.Linq;
using System.Data;

namespace PhoneStoreWeb.Areas.Admin
{
    public class DatabaseHelper
    {
        static PhoneStoreEntities storeDB = new PhoneStoreEntities();

        public static int GetLastProductID()
        {
            return storeDB.Products.OrderByDescending(p => p.ProductID).FirstOrDefault().ProductID;
        }

        public static List<string> GetCategories()
        {
            return storeDB.Categories.Select(c => c.Name).ToList();
        }

        public static List<string> GetManufacturers()
        {
            return storeDB.Manufacturers.Select(m => m.Name).ToList();
        }
        
        public static List<int> GetPhoneGeneral()
        {
            return storeDB.Phone_General.Select(m => m.GeneralID).ToList();
        }

        public static string GetALlPhoneGeneral(int id = 0)
        {
            var a = from q in storeDB.Phone_General
                       where q.GeneralID == id
                       select new { 
                            q.TwoGNetwork
                       };                           
            return a.ToString();
        }

        public static List<string> getall()
        {
            return storeDB.Phone_General.Select(m=>m.TwoGNetwork).ToList();
        }
    }
}